﻿namespace ExamV5.WorkExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmWorkRubricOpertionMore : Page
    {
        protected Button butDefault;
        protected Button butLook;
        protected DropDownList DDLOpertion;
        protected DropDownList DDLSubject;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labRubricError;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtEndDate;
        //protected HtmlInputHidden txtRubricDoc;
        protected TextBox txtStartDate;
        protected UpdatePanel UPPart;

        protected TextBox txtRubricDoc;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            bool flag;
            this.labRubricError.Text = "";
            string str = "";
            string str2 = "";
            string str3 = this.DDLOpertion.SelectedItem.Value;
            switch (str3)
            {
                case null:
                    return;

                case "E":
                    this.labRubricError.Text = "";
                    this.method_2();
                    return;

                case "A":
                    this.method_2();
                    return;

                case "B":
                    str = "";
                    str2 = "update WorkRubric set IsDel='Y' where ID<>0";
                    if (this.ViewState["ManagPower"].ToString() != "Y")
                    {
                        str2 = str2 + " and CreatNumberNO='" + this.httpCookie_0.Value + "'";
                    }
                    if (this.txtStartDate.Text.Trim() != "")
                    {
                        str2 = str2 + " and Convert(dateTime,CreatTime)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
                    }
                    if (this.txtEndDate.Text.Trim() != "")
                    {
                        str2 = str2 + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,CreatTime)";
                    }
                    str2 = str2 + str + " and SubjectID='" + this.DDLSubject.SelectedItem.Value + "'";
                    this.publicFun_0.ExecuteSql(str2 + ";insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('批量禁用[" + this.DDLSubject.SelectedItem.Text + "]科目中的职业测评题目信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                    base.Response.Write("<script>alert('批量禁用试题操作成功！')</script>");
                    return;

                case "C":
                    str = "";
                    str2 = "update WorkRubric set IsDel='N' where ID<>0";
                    if (this.ViewState["ManagPower"].ToString() != "Y")
                    {
                        str2 = str2 + " and CreatNumberNO='" + this.httpCookie_0.Value + "'";
                    }
                    if (this.txtStartDate.Text.Trim() != "")
                    {
                        str2 = str2 + " and Convert(dateTime,CreatTime)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
                    }
                    if (this.txtEndDate.Text.Trim() != "")
                    {
                        str2 = str2 + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,CreatTime)";
                    }
                    str2 = str2 + str + " and SubjectID='" + this.DDLSubject.SelectedItem.Value + "' ";
                    this.publicFun_0.ExecuteSql(str2 + ";insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('批量启用[" + this.DDLSubject.SelectedItem.Text + "]科目中的职业测评题目信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                    base.Response.Write("<script>alert('批量启用试题操作成功！')</script>");
                    return;

                default:
                    {
                        if (!(str3 == "D"))
                        {
                            return;
                        }
                        str = "";
                        str2 = "delete WorkRubric  where ID<>0";
                        string strSql = "select ID from WorkRubric  where ID<>0";
                        if (this.ViewState["ManagPower"].ToString() != "Y")
                        {
                            str2 = str2 + " and CreatNumberNO='" + this.httpCookie_0.Value + "'";
                            strSql = strSql + " and CreatNumberNO='" + this.httpCookie_0.Value + "'";
                        }
                        if (this.txtStartDate.Text.Trim() != "")
                        {
                            str2 = str2 + " and Convert(dateTime,CreatTime)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
                            strSql = strSql + " and Convert(dateTime,CreatTime)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
                        }
                        if (this.txtEndDate.Text.Trim() != "")
                        {
                            str2 = str2 + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,CreatTime)";
                            strSql = strSql + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,CreatTime)";
                        }
                        str2 = str2 + str + " and SubjectID='" + this.DDLSubject.SelectedItem.Value + "'";
                        strSql = strSql + str + " and SubjectID='" + this.DDLSubject.SelectedItem.Value + "'";
                        string str4 = "," + this.publicFun_0.GetValues(strSql);
                        strSql = "select RubricS+RubricD as UseRubric from WorkPaperData where  PaperID in(select PaperID from WorkExamUser where Flag<>'A')";
                        string[] strArray2 = ("," + this.publicFun_0.GetValues(strSql).Replace("#", ",")).Split(new char[] { ',' });
                        flag = false;
                        for (int i = 0; i < strArray2.Length; i++)
                        {
                            if ((strArray2[i].Trim() != "") && (str4.IndexOf("," + strArray2[i].Trim() + ",") != -1))
                            {
                                flag = true;
                                break;
                            }
                        }
                        break;
                    }
            }
            if (!flag)
            {
                this.publicFun_0.ExecuteSql(str2 + ";insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('批量删除[" + this.DDLSubject.SelectedItem.Text + "]科目中的职业测评题目信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                base.Response.Write("<script>alert('批量删除试题操作成功！')</script>");
                //this.txtRubricDoc.Value = "";
                this.txtRubricDoc.Text = "";
            }
            else
            {
                base.Response.Write("<script>alert('因部分试题已被试卷使用并有考生作答记录所以试题无法删除！')</script>");
            }
        }

        protected void butLook_Click(object sender, EventArgs e)
        {
            this.labRubricError.Text = "";
            this.method_4();
        }

        protected void DDLOpertion_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((((this.DDLOpertion.SelectedItem.Value != "B") && (this.DDLOpertion.SelectedItem.Value != "C")) && (this.DDLOpertion.SelectedItem.Value != "D")) && !(this.DDLOpertion.SelectedItem.Value == "E"))
            {
                this.butLook.Visible = false;
            }
            else
            {
                this.butLook.Visible = true;
            }
        }

        private void method_0(string string_0)
        {
            string str = "";
            string str2 = "";
            string str3 = "";
            string str4 = "";
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            Random random = new Random();
            SqlCommand command = null;
            string_0 = string_0.Replace("'", "’").ToLower().Replace("\r\n", "");
            string[] strArray = string_0.Replace("。。", "∷").Split(new char[] { '∷' });
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i].Trim().ToLower().Replace("　", "").Replace("&nbsp;", " ").Replace("<BR />", "").Replace("<br>", "").Replace("<BR>", "").Replace("\r\n", "") != "")
                {
                    int maxValue = 0x2710;
                    maxValue = 0x2710 + i;
                    random.Next(maxValue).ToString();
                    string[] strArray3 = strArray[i].Replace("//", "⊥").Split(new char[] { '⊥' });
                    str = strArray3[0].Trim();
                    for (int j = 0; j < 10; j++)
                    {
                        if ((str.Length > 4) && (str.Substring(0, 4).ToUpper() == "<BR>"))
                        {
                            str = str.Substring(4);
                        }
                        if ((str.Length > 6) && (str.Substring(0, 6).ToLower() == "&nbsp;"))
                        {
                            str = str.Substring(6);
                        }
                    }
                    str2 = this.method_3(strArray3[1]) + "#" + this.method_3(strArray3[2]) + "#" + this.method_3(strArray3[3]) + "#" + this.method_3(strArray3[4]) + "#" + this.method_3(strArray3[5]) + "#" + this.method_3(strArray3[6]);
                    str3 = strArray3[7].Trim().ToUpper().Replace("＃", "#").Replace("　", "").Replace("&nbsp;", " ").Replace("<BR />", "").Replace("<BR>", "").Replace("Ａ", "A").Replace("Ｂ", "B").Replace("Ｃ", "C").Replace("Ｄ", "D").Replace("Ｅ", "E").Replace("Ｆ", "F");
                    str4 = "Insert into WorkRubric(RubricType,SubjectID,RubricTitle,OptionAnswer,OKAnswer,CreatTime,CreatNumberNO,IsDel) Values(";
                    command = new SqlCommand(str4 + "@RubricType,@SubjectID,@RubricTitle,@OptionAnswer,@OKAnswer,@CreatTime,@CreatNumberNO,@IsDel)", connection);
                    command.Parameters.Add("@RubricType", SqlDbType.Char, 1).Value = "A";
                    command.Parameters.Add("@SubjectID", SqlDbType.Int).Value = this.DDLSubject.SelectedItem.Value;
                    command.Parameters.Add("@RubricTitle", SqlDbType.Text).Value = str;
                    command.Parameters.Add("@OptionAnswer", SqlDbType.Text).Value = str2;
                    command.Parameters.Add("@OKAnswer", SqlDbType.Text).Value = str3;
                    command.Parameters.Add("@CreatTime", SqlDbType.VarChar, 20).Value = DateTime.Now.ToString();
                    command.Parameters.Add("@CreatNumberNO", SqlDbType.VarChar, 20).Value = this.httpCookie_0.Value;
                    command.Parameters.Add("@IsDel", SqlDbType.Char, 1).Value = "N";
                    command.ExecuteNonQuery();
                    command.Dispose();
                }
            }
            this.publicFun_0.ExecuteSql("insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('批量添加[" + this.DDLSubject.SelectedItem.Text + "]科目职业测评题目信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
            base.Response.Write("<script>alert('批量添加试题操作成功！')</script>");
            //this.txtRubricDoc.Value = "";
            this.txtRubricDoc.Text = "";
            this.labRubricError.Text = "";
        }

        private string method_1(string string_0)
        {
            string_0 = string_0.ToLower();
            string_0 = string_0.Replace("<p><br>", "");
            string_0 = string_0.Replace("<p><br><br>", "");
            string_0 = string_0.Replace("<p><br><br><br>", "");
            string_0 = string_0.Replace("<p><br><br><br><br>", "");
            string_0 = string_0.Replace("<p><br />", "");
            string_0 = string_0.Replace("<p><br /><br />", "");
            string_0 = string_0.Replace("<p><br /><br /><br />", "");
            string_0 = string_0.Replace("<p><br /><br /><br /><br />", "");
            string_0 = string_0.Replace("<p>", "");
            string_0 = string_0.Replace("<p align=right>", "");
            string_0 = string_0.Replace("<p align=center>", "");
            string_0 = string_0.Replace("<p align=left>", "");
            string_0 = string_0.Replace("</p>", "");
            string_0 = string_0.Replace("\r\n", "");
            string_0 = string_0.Replace("http://", "");
            return string_0;
        }

        private void method_2()
        {
            //string str = this.method_1(this.txtRubricDoc.Value.Trim());
            string str = this.method_1(this.txtRubricDoc.Text.Trim());
            bool flag = false;
            string str2 = "";
            string str3 = "";
            string str5 = "";
            string[] strArray = str.ToUpper().Replace("　", "").Replace("&nbsp;", " ").Replace("<BR />", "").Replace("<BR>", "").Replace("。。", "∷").Split(new char[] { '∷' });
            for (int i = 0; i < strArray.Length; i++)
            {
                string[] strArray4;
                if (strArray[i].Trim() != "")
                {
                    strArray4 = strArray[i].Replace("//", "⊥").Split(new char[] { '⊥' });
                    str2 = strArray[i];
                    if (strArray4.Length != 8)
                    {
                        str5 = "A";
                        flag = true;
                        if (strArray4[0].Trim() == "")
                        {
                            str2 = strArray[i];
                        }
                        else
                        {
                            str2 = strArray4[0].Trim();
                        }
                        break;
                    }
                    str3 = this.method_3(strArray4[1]) + "#" + this.method_3(strArray4[2]) + "#" + this.method_3(strArray4[3]) + "#" + this.method_3(strArray4[4]) + "#" + this.method_3(strArray4[5]) + "#" + this.method_3(strArray4[6]);
                    string[] strArray3 = strArray4[7].Trim().Replace("＃", "#").Split(new char[] { '#' });
                    str3 = str3.Replace("#####", "").Replace("####", "").Replace("###", "").Replace("##", "");
                    if (str3.Substring(str3.Length - 1, 1) == "#")
                    {
                        str3 = str3.Substring(0, str3.Length - 1);
                    }
                    string[] strArray2 = str3.Split(new char[] { '#' });
                    if (strArray2.Length != strArray3.Length)
                    {
                        str5 = "B";
                        flag = true;
                        str2 = strArray4[0].Trim();
                        break;
                    }
                    for (int j = 0; j < strArray2.Length; j++)
                    {
                        if (strArray2[j].Trim() != "")
                        {
                            if (strArray3[j].Trim() == "")
                            {
                                goto Label_02EC;
                            }
                            try
                            {
                                Convert.ToDouble(strArray3[j].Trim());
                            }
                            catch
                            {
                                str5 = "C";
                                flag = true;
                                str2 = strArray4[0].Trim();
                                base.Response.Write("<script>alert('" + str2 + "试题选项或选项分值错误！')</script>");
                                break;
                            }
                        }
                    }
                }
                continue;
                Label_02EC:
                str5 = "C";
                flag = true;
                str2 = strArray4[0].Trim();
                base.Response.Write("<script>alert('" + str2 + "试题有答案或选项错误！')</script>");
            }
            if (!flag)
            {
                if (this.DDLOpertion.SelectedItem.Value == "A")
                {
                    this.method_0(str);
                }
                else
                {
                    base.Response.Write("<script>alert('所有试题格式完全正确！')</script>");
                }
            }
            else
            {
                string str6 = str5.Trim();
                if (str6 != null)
                {
                    if (str6 != "A")
                    {
                        if (!(str6 == "B"))
                        {
                            if (str6 == "C")
                            {
                                base.Response.Write("<script>alert('" + str2 + "试题选项或选项分值错误！')</script>");
                            }
                        }
                        else
                        {
                            base.Response.Write("<script>alert('" + str2 + "试题有答案或选项错误！')</script>");
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('" + str2 + "试题有格式错误！')</script>");
                    }
                }
                this.labRubricError.Text = str2 + "试题有格式错误！";
            }
        }

        private string method_3(string string_0)
        {
            return string_0.Trim().Replace("#", "＃").Replace("A．", "").Replace("A.", "").Replace("A、", "").Replace("A ", "").Replace("(A)", "").Replace("（A）", "").Replace("(a)", "").Replace("（a）", "").Replace("（Ａ）", "").Replace("#", "＃").Replace("B．", "").Replace("B.", "").Replace("B、", "").Replace("B ", "").Replace("(B)", "").Replace("（B）", "").Replace("(b)", "").Replace("（b）", "").Replace("（Ｂ）", "").Replace("#", "＃").Replace("C．", "").Replace("C.", "").Replace("C、", "").Replace("C ", "").Replace("(C)", "").Replace("（C）", "").Replace("(c)", "").Replace("（c）", "").Replace("（Ｃ）", "").Replace("#", "＃").Replace("D．", "").Replace("D.", "").Replace("D、", "").Replace("D ", "").Replace("(D)", "").Replace("（D）", "").Replace("(d)", "").Replace("（d）", "").Replace("（Ｄ）", "").Replace("#", "＃").Replace("E．", "").Replace("E.", "").Replace("E、", "").Replace("E ", "").Replace("(E)", "").Replace("（E）", "").Replace("(e)", "").Replace("（e）", "").Replace("（Ｅ）", "").Replace("#", "＃").Replace("F．", "").Replace("F.", "").Replace("F、", "").Replace("F ", "").Replace("(F)", "").Replace("（F）", "").Replace("(f)", "").Replace("（f）", "").Replace("（Ｆ）", "");
        }

        private void method_4()
        {
            //this.txtRubricDoc.Value = "";
            this.txtRubricDoc.Text = "";
            string str = "";
            string str2 = "";
            string str3 = "";
            string str4 = "";
            string cmdText = "select RubricTitle,OptionAnswer,OKAnswer from WorkRubric where ID<>0";
            if (this.ViewState["ManagPower"].ToString().Trim() != "Y")
            {
                cmdText = cmdText + " and CreatNumberNO='" + this.httpCookie_0.Value + "'";
            }
            cmdText = cmdText + str4 + " and SubjectID='" + this.DDLSubject.SelectedItem.Value + "' and RubricType='A'";
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                str = reader["RubricTitle"].ToString();
                str2 = reader["OptionAnswer"].ToString().Trim().Replace("#", "//");
                str3 = reader["OKAnswer"].ToString().Trim();
                //this.txtRubricDoc.Value = this.txtRubricDoc.Value + "<P>" + str + "//" + str2 + "//" + str3 + "。。</P>";
                this.txtRubricDoc.Text = this.txtRubricDoc.Text + str + "//" + str2 + "//" + str3 + "。。\n";
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) == 0x3a)
                {
                    base.Response.Write("<script>alert('该版本为特惠版，此功能未开放！')</script>");
                }
                else if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select AddRubric,ManagRubric from UserPower where UserCode='" + this.httpCookie_0.Value + "'", connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.ViewState["AddPower"] = reader["AddRubric"].ToString();
                            this.ViewState["ManagPower"] = reader["ManagRubric"].ToString();
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        if (!((this.ViewState["AddPower"].ToString().Trim() != "Y") ? !(this.ViewState["ManagPower"].ToString().Trim() != "Y") : true))
                        {
                            this.butDefault.Visible = false;
                            base.Response.Write("<script>alert('添加或管理题库权限未开放！')</script>");
                        }
                        else
                        {
                            this.publicFun_0.LoadSubjectInfo(this.DDLSubject, this.httpCookie_0.Value, this.ViewState["ManagPower"].ToString(), "E", this.httpCookie_3.Value);
                            this.DDLSubject.Items.Insert(0, new ListItem("--请选择所属科目信息--", "0"));
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

